//
//  MCDiscountPayHeadView.swift
//  StoreManage
//
//  Created by MC on 2017/12/19.
//  Copyright © 2017年 MC. All rights reserved.
//

import UIKit

class MCMyCommissionHeaderView: UIView {
    
    
    var dataDict = Dictionary<String,Any>() {
        didSet {
            // 当月总佣金
            let totalCommission = dataDict["totalCommission"] as? NSNumber ?? 0
            let moneyStr = MCString_judgemantDecimalsIsZero(figure: totalCommission.intValue)
            moneyLabel.attributedText = moneyStr.MCAttributedString_font(font: 16, range: NSRange.init(location: 0, length: 1))
            
            // 当月在途佣金
            let onTheWayCommision = dataDict["onTheWayCommision"] as? NSNumber ?? 0
            let commisson = " 在途佣金: " + MCString_judgemantDecimalsIsZero(figure: onTheWayCommision.intValue)
            warningButton.setTitle(commisson, for: .normal)
        }
    }
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = UIColor.white
        self.frame = CGRect.init(x: 0, y: 0, width: 0, height: MCScreenWidth*0.4 + 40)
        setUpSubViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpSubViews() {
        
        self.addSubview(bigImageView)
        bigImageView.snp.remakeConstraints { (make) ->Void in
            make.edges.equalTo(self).inset(UIEdgeInsetsMake(0, 0, 40, 0))
        }

        self.addSubview(promptLabel)
        promptLabel.snp.remakeConstraints { (make) ->Void in
            make.left.bottom.right.equalTo(self)
            make.height.equalTo(40)
        }

        
        bigImageView.addSubview(calendarButton)
        calendarButton.snp.remakeConstraints { (make) ->Void in
            make.left.top.equalTo(15)
            make.size.equalTo(CGSize.init(width: 20, height: 20))
        }
        
        bigImageView.addSubview(timeButton)
        timeButton.snp.remakeConstraints { (make) ->Void in
            make.left.equalTo(calendarButton.snp.right).offset(5)
            make.centerY.equalTo(calendarButton)
            make.size.equalTo(CGSize.init(width: 90, height: 20))
        }

        


        
        bigImageView.addSubview(moneyLabel)
        moneyLabel.snp.remakeConstraints { (make) ->Void in
            make.centerY.equalTo(bigImageView).offset(0)
            make.centerX.equalTo(bigImageView)
        }
        
        bigImageView.addSubview(promptTopLabel)
        promptTopLabel.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(bigImageView)
            make.bottom.equalTo(moneyLabel.snp.top).offset(-15)
        }
        
        bigImageView.addSubview(warningButton)
        warningButton.snp.remakeConstraints { (make) ->Void in
            make.centerX.equalTo(bigImageView)
            make.top.equalTo(moneyLabel.snp.bottom).offset(15)
        }

    }
    
    lazy var bigImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "Reuse_bgImage")
        imageView.isUserInteractionEnabled = true
        return imageView
    }()
    
    lazy var timeButton: MCReverseHorizontalButton = {
        let button = MCReverseHorizontalButton()
        button.iconImageView.image = #imageLiteral(resourceName: "Reuse_triangle_black_bottom").MCImageWithTintColor(color: UIColor.white)
        button.nameLabel.text = "XXX"
        button.nameLabel.textColor = UIColor.white
        button.backgroundColor = UIColor.init(white: 0, alpha: 0.1)
        return button
    }()
    
    lazy var promptTopLabel : UILabel = {
        let label = UILabel()
        label.textColor = UIColor.white
        label.font = MCFont(13)
        label.text = "收获佣金"
        return label
    }()

    
    lazy var moneyLabel : UILabel = {
        let label = UILabel()
        label.textColor = UIColor.white
        label.font = MCFont(40)
        label.text = "¥0"
        return label
    }()
    
    lazy var calendarButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.setImage(#imageLiteral(resourceName: "Mine_calendar"), for: UIControlState.normal)
        return button
    }()
    
    lazy var warningButton: UIButton = {
        let button = UIButton.init(type: UIButtonType.custom)
        button.setImage(#imageLiteral(resourceName: "Order_warning_gray").MCImageWithTintColor(color: UIColor.white), for: UIControlState.normal)
        button.titleLabel?.font = MCFont(12)
        button.setTitleColor(UIColor.white, for: .normal)
        return button
    }()
    
    lazy var promptLabel : UILabel = {
        let label = UILabel()
        label.textColor = UIColor.black
        label.font = MCFont(14)
        label.text = "      收支明细"
        return label
    }()
}




